package test01;
import java.util.*;

public class Test_1062_04 {
    static List<StringBuilder> list = new ArrayList<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        for (int i = 0; i <= t; i++) {
            list.add(new StringBuilder(sc.nextLine()));
            ts();
            list.clear();
        }
    }

    public static void ts() {
        int start = 0;

        for (StringBuilder stringBuilder : list) {
            stringBuilder.reverse();
            Stack<String> stack = new Stack<>();
            for (int i = 0; i < stringBuilder.length(); i++) {
                if (stringBuilder.charAt(i) == ' ') {
                    stack.push(stringBuilder.substring(start, i));
                    stack.push(" ");
                    start = i + 1;
                    i++;
                }
                if (i + 1 == stringBuilder.length()) {
                    stack.push(stringBuilder.substring(start));
                    start = 0;
                }
            }
            while (!stack.isEmpty()) {
                System.out.print(stack.pop());
            }
            System.out.println();
        }
    }
}
